package com.salton123.soulove.sailfish.video.ui.fm

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.salton123.app.BaseApplication
import com.salton123.soulove.app.BuildConfig
import com.salton123.soulove.common.Constants
import com.salton123.soulove.app.R
import kotlinx.android.synthetic.main.comp_rate_us.*

/**
 * User: newSalton@outlook.com
 * Date: 2019/2/19 14:20
 * ModifyTime: 14:20
 * Description:
 */
@Route(path = Constants.Router.Video.RATE_US)
class RateUsPopupComp : FullScreenDialogFragment() {

    companion object {
    }

    override fun getLayoutId(): Int = R.layout.comp_rate_us

    override fun initViewAndData(savedInstanceState: Bundle?) {
        tvCancel.setOnClickListener {
            dismissAllowingStateLoss()
        }
        tvFiveStar.setOnClickListener {

            val packageName = BaseApplication.sInstance.packageName
            var stringBuilder: StringBuilder
            try {
                stringBuilder = StringBuilder()
                stringBuilder.append("market://details?id=")
                stringBuilder.append(packageName)
                activity().startActivity(Intent("android.intent.action.VIEW", Uri.parse(stringBuilder.toString())))
            } catch (unused: ActivityNotFoundException) {
                stringBuilder = StringBuilder()
                stringBuilder.append("https://play.google.com/store/apps/details?id=")
                stringBuilder.append(packageName)
                activity().startActivity(Intent("android.intent.action.VIEW", Uri.parse(stringBuilder.toString())))
            }
            dismissAllowingStateLoss()
        }
        tvFourStar.setOnClickListener {
            dismissAllowingStateLoss()
            val intent = Intent("android.intent.action.SENDTO")
            intent.data = Uri.parse("mailto:newsalton@163.com")
            intent.putExtra("android.intent.extra.SUBJECT", "Eleph Player - Your Video Player And Cleaner, Android")
            val stringBuilder = StringBuilder()
            stringBuilder.append("Eleph Player_Android_" + BuildConfig.VERSION_NAME + "_" + BuildConfig.GIT_HASH)
            stringBuilder.append(Build.VERSION.SDK_INT)
            stringBuilder.append('_')
            stringBuilder.append(Build.MODEL)
            stringBuilder.append(10)
            intent.putExtra("android.intent.extra.TEXT", stringBuilder.toString())
            activity().startActivity(intent)
        }
    }
}
